package cn.jindan.com;

import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.bcel.classfile.EnumElementValue;

public class MyServlet implements Servlet {

	private ServletContext mycontext;
	
	public MyServlet() {
		System.out.println("myservlet");
	}
	
	@Override
	public void destroy() {
		System.out.println("destroy");
	}

	@Override
	public ServletConfig getServletConfig() {
		System.out.println("getServletConfig");
		return null;
	}

	@Override
	public String getServletInfo() {
		System.out.println("getServletInfo");
		return null;
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		  this.mycontext  =      config.getServletContext();
		  
//		 Enumeration<String> env =   config.getInitParameterNames();
//	     while(env.hasMoreElements()) {
//	    	 String string  = env.nextElement();
//	    	 String value = config.getInitParameter(string);
//	    	 System.out.println(string+"----"+value); 
//	     }
		 
		System.out.println( "init");
	}

	@Override
	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
		
//		res.setContentType("application/msword");
		
	   String name = req.getParameter("username"); 
	   
	   if(name.equals("12312")) {
		   res.getWriter().print("登录成功");
	   }
	
		
		
//		Properties pos =new Properties();
//		String path = mycontext.getRealPath("ceshi.properties");	
//		pos.load(new FileReader(path));	
//		System.out.println( pos.getProperty("use"));
		
		
		
//	    res.getWriter().print(mycontext.getInitParameter("context1"));	
//		HttpServletResponse  se  =   (HttpServletResponse) res;
//	     mycontext.setAttribute("123", "qweqwe");
//		System.out.println("service");
	}
}
